var layerLoad;
var layerNumber;
$(function(){
	initOrderList(1);
	/**
	 * 列表初始化
	 * @param currentPage
	 */
	function initOrderList(currentPage){
		$('#total-price-update-number').html('0');
		$('#total-price-update').css('bottom','-41px');
		var serOrder = {
			currentPage : currentPage,
			pageSize : 10,
			sysVehiclesId : $('#sysVehiclesId').val(),
			serOrderType : $('#serOrderType').val(),
			serOrderState : $('#orderState').val(),
			orderSendTime : $('#serOrderSendTime').val(),
			searchName: $('#sysOrderListSearchName').val(),
			keyword:$("#adminsSarchName").val()
		}
		$.ajax({
			url : $api.order.selectOrders,
			type : "POST",
			dataType : "JSON",
			contentType : 'application/json',
			data : JSON.stringify(serOrder),
			beforeSend : function () {
				layerLoad = layer.load();
			},
			success : function(data) {
				if(!$checkRemouteStatus(data)){
					layer.close(layerLoad);
					return;
				}
				layui.use('laytpl', function() {
					var laytpl = layui.laytpl;
					laytpl(sysOrderListTpl.innerHTML).render(data, function(html) {
						$('#sys-order-list-body').html(html)
					});
				});
				layui.use('laypage', function() {
					layui.laypage({
						cont: $('#sys-order-list-body-page'),
						pages: data.totalPage,
						groups: 2,
						curr: data.currentPage,
						skip: true,
                        skin:'#0e90d2',
						jump: function (obj,first) {
							if(!first){
								initOrderList(obj.curr);
							}
						}
					});
				});
				layer.close(layerLoad);
			},
			error : function() {
				layer.close(layerLoad);
				layer.msg('网络异常，请稍后再试', {icon: 2});
			}
		});
	};
	/**
	 * 搜索
	 */
	$('#sys-product-form-list-search').submit(function(e){
		e.preventDefault();
		initOrderList(1);
	});
	/**
	 * 订单详情查询
	 */
	$('#sys-order-list-body').on('click','.btn-order-list-detail',function(){
		$.ajax({
			url : $api.order.selectOrderByOrderId+"?orderId="+$(this).attr('orderId'),
			type : "GET",
			dataType : "JSON",
			beforeSend : function () {
				layerLoad = layer.load();
			},
			success : function(data) {
				if(!$checkRemouteStatus(data)){
					layer.close(layerLoad);
					return;
				}
				var dataObj=data.msg;
                $("#sn").text(dataObj.sn);
				$("#memberName").text(dataObj.memberName);
                $("#address").text(dataObj.address);
                $("#receiverPhone").text(dataObj.receiverPhone);
                $("#shippingMethod").text(dataObj.shippingMethod);
                $("#snOut").text(dataObj.snOut);
                $("#intro").text(dataObj.intro);
                $("#amountPaid").text(dataObj.amountPaid);
                $("#receiverName").text(dataObj.receiverName);
                var orderStatus;
                if(dataObj.orderStatus=="0"){
                	orderStatus="未支付";
                }else if(dataObj.orderStatus=="1"){
                	orderStatus="已支付";
                }else if(dataObj.orderStatus=="2"){
                	orderStatus="配送中";
                }else if(dataObj.orderStatus=="3"){
                	orderStatus="待发货";
                }else if(dataObj.orderStatus=="4"){
                	orderStatus="已发货";
                }else if(dataObj.orderStatus=="5"){
                	orderStatus="待评价";
                }else if(dataObj.orderStatus=="6"){
                	orderStatus="已完成";
                }else if(dataObj.orderStatus=="7"){
                	orderStatus="已取消";
                }
                $("#orderStatus").text(orderStatus);
				layer.close(layerLoad);
				console.log(dataObj.orderItemBeans);
                layui.use('laytpl', function() {
                    var laytpl = layui.laytpl;
                    laytpl(sysSpecificationValuesListTpl.innerHTML).render(dataObj, function(html) {
                        $('#specProduct').html(html)
                    });
                });
                layerNumber=layer.open({
                    type : 1,
                    title : '订单详情',
                    area : 'auto',
                    maxWidth : '1000px',
                    content : $('#system-member-update-model'),
                    cancel : function(){
                    }
                });
			},
			error : function() {
				layer.close(layerLoad);
				layer.msg('网络异常，请稍后再试', {icon: 2});
			}
		});
	});
	/*model关闭*/
    $("#modelClose").click(function(){
        layer.close(layerNumber);
    });
});

